class PageRoute < ActiveRecord::Base
  self.primary_key = :id
  ActiveRecord::Base.pluralize_table_names = false
  after_save :reload_routes
  def route_name
	name ? name.gsub(/\W+/, ' ').strip.downcase.gsub(/\ +/, '-').gsub('-', '_') : nil
  end
  alias_method :as, :route_name

  def to
    "#{controller}##{action}"
  end

  # Returns which methods this route can be via. Defaults to [:get, :post] if not specified.
  def via
    if methods.empty?
      methods << :get << :post
    end
  end

  def self.reload_routes
    Rails.application.reload_routes!
  end

  def reload_routes
    PageRoute.reload_routes
  end
end
